package client;

import entity.User;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import service.IUserService;

/**
 * @author liujw
 * @create 2020/9/10 00:16
 */
public class WsClient {
    public static void main(String[] args) {
        //编写客户端 调用发布WebService服务
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();

        jaxWsProxyFactoryBean.getInInterceptors().add(new LoggingInInterceptor());
        jaxWsProxyFactoryBean.getOutInterceptors().add(new LoggingOutInterceptor());

        jaxWsProxyFactoryBean.setServiceClass(IUserService.class);
        jaxWsProxyFactoryBean.setAddress("http://localhost:8888/userService");

        //调用远程服务代理对象
        IUserService proxy = (IUserService) jaxWsProxyFactoryBean.create();
        //调用代理对象任何一个方法，都将网络调用web服务
        System.out.println(proxy.sayHello("你好"));
        User user = new User();
        user.setUsername("xiaoming");
        System.out.println(proxy.findCarsByUser(user));

        System.out.println(proxy.findOneCar(user));
    }
}
